package com.roger.ats.init;

import android.os.SystemClock;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.UiCollection;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import android.util.Log;

import com.roger.ats.init.cases.AccountInit;
import com.roger.ats.init.cases.AppInit;
import com.roger.ats.init.cases.HomeScreenInit;
import com.roger.ats.init.util.CfgUtils;
import com.roger.ats.init.util.LogUtils;
import com.roger.uia.helper.UiBase;
import com.roger.uia.helper.UiWatch;
import com.roger.uia.helper.manager.Package;
import com.roger.uia.helper.manager.Wifi;
import com.roger.uia.helper.util.FileUtils;
import com.roger.uia.helper.util.StrUtils;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MainAmar extends UiBase {
    private static final String TAG = "Test" + MainAmar.class.getSimpleName();
    private static LogUtils logUtils = new LogUtils();
    private static CfgUtils cfgUtils = new CfgUtils();

    @BeforeClass
    public static void beforeClass() throws Throwable{
        Package.pac().grantAllPerms(InstrumentationRegistry.getTargetContext().getPackageName());
        if(!mDevice.isScreenOn()) mDevice.wakeUp();
        initLogs();
    }

    @Before
    public void setUp() {
        Log.d(TAG, "-- set up --");
        UiWatch.getWatcher().runErrorWatcher();
        UiWatch.getWatcher().runSpecialWatcher();
    }

    @After
    public void tearDown() {
        Log.d(TAG, "-- tear down --");
        UiWatch.getWatcher().removeErrorWatcher();
        UiWatch.getWatcher().removeSpecialWatcher();
    }

    @AfterClass
    public static void afterClass() throws Throwable{
        //mDevice.executeShellCommand("reboot");
    }

    @Test
    public void Case001_setLockNone(){
        mDevice.pressHome();
        try {
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], StrUtils.settingSecurity);
            waitObj(objSelect[3], StrUtils.settingList_Q, 3);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], StrUtils.ScreenLock);
            waitClickObj(objSelect[2], StrUtils.lockNone, 3);
        }catch (Throwable e){
            e.printStackTrace();
        }finally {
            mDevice.pressHome();
        }
    }

    @Test
    public void Case002_disableApp(){
        logUtils.printLog("==start disable app==");
        String[] appList=cfgUtils.getPacInfo(filePath+"ATS/config/blacklist.ini");
        for (String pac : appList){
            if(Package.pac().isAppInstalled(pac)) {
                try {
                    disableApp(pac);
                    logUtils.printLog("disable app success : " + pac);
                } catch (Throwable e) {
                    logUtils.printLog("disable app fail : " + pac);
                }
            } else
                logUtils.printLog("not installed : " + pac);
        }
    }

    @Test
    public void Case003_grantApp(){
        logUtils.printLog("==start grant app==");
        String[] appList=cfgUtils.getPacInfo(filePath+"ATS/config/whitelist.ini");
        for (String pac : appList){
            if(Package.pac().isAppInstalled(pac)) {
                try {
                    Package.pac().grantAllPerms(pac);
                    logUtils.printLog("grant app success : " + pac);
                } catch (Throwable e) {
                    logUtils.printLog("grant app fail : " + pac);
                }
            } else
                logUtils.printLog("not installed : " + pac);
        }
    }

    @Test
    public void Case004_closeAutoUpdate(){
        String pac = "com.android.vending";
        String menu = "com.android.vending:id/unauth_home_overflow";
        String btn = "com.android.vending:id/checkbox";
        mDevice.pressHome();
        logUtils.printLog("==start close auto update==");
        if (Package.pac().isAppInstalled(pac)) {
            try {
                openApp(pac);
                waitClickObj(objSelect[3], menu, 10);
                waitObjCheck(objSelect[3], btn, 5);
                if (objChecked(objSelect[3], btn)) {
                    clickObj(objSelect[3], btn);
                    waitClickObj(objSelect[3], menu, 5);
                }
                checkPoint("check status", !objChecked(objSelect[3], btn));
                logUtils.printLog("close auto update success");
            } catch (Throwable e) {
                logUtils.printLog("close auto update fail");
            } finally {
                mDevice.pressBack();
                mDevice.pressHome();
            }
        } else {
            logUtils.printLog("not found Google Play");
        }
    }

    @Test
    public void Case005_connWifi() {
        mDevice.pressHome();
        String ifConn = cfgUtils.getCfg("wifi_conn=");
        String wifiName = cfgUtils.getCfg("wifi_name=");
        String wifiPwd = cfgUtils.getCfg("wifi_pwd=");
        UiObject menuText = mDevice.findObject(new UiSelector().textMatches(wifiName));
        String success = "(?i)" + wifiName + ",Connected.*|" + wifiName + ",已连接.*";
        UiScrollable secMenuList = new UiScrollable(new UiSelector().resourceId(StrUtils.settingList_Q));
        logUtils.printLog("==start connect wifi==");
        for (int i = 0; i < 3; i++) {
            try {
                if (ifConn.equals("true")) {
                    if (!Wifi.wifi().getWifiSaved().contains(wifiName)) {
                        enterWLAN();
                        for (int j = 0; j < 3; j++) {
                            secMenuList.scrollIntoView(menuText);
                            if (menuText.exists()) {
                                menuText.clickAndWaitForNewWindow();
                                break;
                            }
                        }
                        if (!wifiPwd.equals("null")) {
                            waitObjCheck(objSelect[3], StrUtils.password, 5);
                            inputTxtToObj(objSelect[3], StrUtils.password, wifiPwd);
                            waitClickObj(objSelect[3], "com.android.settings:id/wifi_advanced_togglebox", 3);
                            waitClickObj(objSelect[3], "com.android.settings:id/privacy_settings", 3);
                            waitClickObj(objSelect[0], "使用设备 MAC", 3);

                            waitClickObj(objSelect[2], StrUtils.connect, 10);
                        }
                        waitObjCheck(objSelect[6], success, 30);
                        logUtils.printLog("connect wifi success : " + wifiName);
                        break;
                    } else {
                        logUtils.printLog("already saved wifi : " + wifiName);
                        break;
                    }
                }
            } catch (Throwable e) {
                logUtils.printLog("connect wifi fail : " + wifiName);
            } finally {
                mDevice.pressHome();
            }
        }
    }

    @Test
    public void Case006_AccountInit() {
        AccountInit.launchPOP3();
        AccountInit.launchIMAP();
    }

    @Test
    public void Case007_launchLenovoAccount() {
        mDevice.pressHome();
        String account = cfgUtils.getCfg("lenovo_account=");
        String pwd = cfgUtils.getCfg("lenovo_pwd=");
        if (!account.equals("null")) {
            logUtils.printLog("==start set lenovo email==");
            for (int i = 0; i < 3; i++) {
                try {
                    openApp(StrUtils.settingPac);
                    waitObj(objSelect[3], StrUtils.settingList_Q, 10);
                    new UiScrollable(new UiSelector().resourceId(StrUtils.settingList_Q)).scrollIntoView(getObj(objSelect[2], "(?i)Lenovo ID"));
                    if (!existObj(objSelect[1], "@lenovo.com")) {
                        startAct(Settings.ACTION_ADD_ACCOUNT);
                        waitClickObj(objSelect[2], "联想帐号", 10);
                        waitClickObj(objSelect[2], "登录|邮箱登录", 5);
                        waitObjCheck(objSelect[3], "com.lenovo.lsf:id/at_account", 5);
                        inputTxtToObj(objSelect[3], "com.lenovo.lsf:id/at_account", account);
                        inputTxtToObj(objSelect[3], "com.lenovo.lsf:id/et_password", pwd);
                        waitClickObj(objSelect[3], "com.lenovo.lsf:id/b_login", 5);
                        SystemClock.sleep(waitTime * 5);
                        mDevice.pressHome();
                        openApp(StrUtils.settingPac);
                        waitObj(objSelect[3], StrUtils.settingList_Q, 10);
                        new UiScrollable(new UiSelector().resourceId(StrUtils.settingList_Q)).scrollIntoView(getObj(objSelect[0], "Lenovo ID"));
                        if (!existObj(objSelect[0], "Lenovo ID"))
                            scrollReidClickObj(StrUtils.settingList_Q, objSelect[0], "用户和帐号");
                        checkPoint("check status", existObj(objSelect[1], "@lenovo.com"));
                        logUtils.printLog("set lenovo email success");
                        break;
                    } else {
                        logUtils.printLog("lenovo account already exist");
                        break;
                    }
                } catch (Throwable e) {
                    logUtils.printLog("set lenovo email fail");
                } finally {
                    mDevice.pressHome();
                }
            }
        }
    }

    @Test
    @Ignore("no this function at Amar")
    public void Case008_setDesktop() {
        mDevice.pressHome();
        logUtils.printLog("==start set desktop style==");
        try {
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], StrUtils.settingDisplay);
            waitObj(objSelect[3], StrUtils.settingList_Q, 3);
            clickIfObjExist(objSelect[2], StrUtils.advanced);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], "桌面风格");
            waitClickObj(objSelect[2], "抽屉模式|抽屉风格", 3);
            logUtils.printLog("set desktop style success");
        } catch (Throwable e) {
            logUtils.printLog("set desktop style fail");
        } finally {
            mDevice.pressHome();
        }
    }

    @Test
    public void Case009_setNavigation() {
        mDevice.pressHome();
        logUtils.printLog("==start set navigation bar==");
        try {
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], StrUtils.settingDisplay);
            waitObj(objSelect[3], StrUtils.settingList_Q, 3);
            clickIfObjExist(objSelect[2], StrUtils.advanced);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], "导航栏|导航栏模式|系统导航");
            waitObj(objSelect[3], StrUtils.settingList_Q, 3);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], "“三按钮”导航");
            logUtils.printLog("set navigation bar success");
        } catch (Throwable e) {
            logUtils.printLog("set navigation bar fail");
        } finally {
            mDevice.pressHome();
        }
    }

    @Test
    public void Case010_changeWallpaper() {
        mDevice.pressHome();
        logUtils.printLog("==start set wallpaper==");
        try {
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], StrUtils.settingDisplay);
            waitObj(objSelect[3], StrUtils.settingList_Q, 3);
            clickIfObjExist(objSelect[2], StrUtils.advanced);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], "壁纸");
            waitObj(objSelect[2], "选择壁纸来源", 3);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], "壁纸");
            waitClickObj(objSelect[2], "我的照片", 3);
            waitClickObj(objSelect[4], "显示根目录", 3);
            waitClickObj(objSelect[2], "图片", 3);
            waitClickObj(objSelect[2], "DCIM", 3);
            waitClickObj(objSelect[6], "背景.png.*", 5);
            waitClickObj(objSelect[2], "设置壁纸", 5);
            waitClickIfObjExist(objSelect[2], "主屏幕", 5);
            waitObj(objSelect[3], StrUtils.settingList_Q, 5);
            logUtils.printLog("set wallpaper success");
        } catch (Throwable e) {
            logUtils.printLog("set wallpaper fail");
        } finally {
            mDevice.pressHome();
        }
    }

    @Test
    @Ignore("no need any more")
    public void Case011_setPinLock() {
        mDevice.pressHome();
        logUtils.printLog("==start set screen lock==");
        try {
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], StrUtils.settingSecurity);
            waitObj(objSelect[3], StrUtils.settingList_Q, 3);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], StrUtils.ScreenLock);
            waitClickObj(objSelect[0], "PIN 码", 3);
            waitObj(objSelect[0], "设置屏幕锁定", 3);
            inputTxtToObj(objSelect[3], "com.android.settings:id/password_entry", "1111");
            waitClickObj(objSelect[2], "下一步", 3);
            waitObj(objSelect[0], "重新输入 PIN 码", 3);
            inputTxtToObj(objSelect[3], "com.android.settings:id/password_entry", "1111");
            waitClickObj(objSelect[2], "确认|确定", 3);
            waitClickObj(objSelect[0], "完成", 5);
            waitObj(objSelect[2], StrUtils.ScreenLock, 5);
            checkPoint("check status", existObj(objSelect[0], "PIN 码"));
            logUtils.printLog("set screen lock success");
        } catch (Throwable e) {
            logUtils.printLog("set screen lock fail");
        } finally {
            mDevice.pressHome();
        }
    }

    @Test
    @Ignore("just as default")
    public void Case012_setBattery() {
        mDevice.pressHome();
        logUtils.printLog("==start set battery==");
        try {
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], StrUtils.settingBattery);
            waitObj(objSelect[3], StrUtils.settingList_Q, 3);
            UiScrollable list = new UiScrollable(new UiSelector().resourceId(StrUtils.settingList_Q));
            list.scrollIntoView(getObj(objSelect[2], "电池保护模式"));
            UiObject objParent = getObj(objSelect[2], "电池保护模式").getFromParent(new UiSelector());
            UiObject obj = getObjSameLine(new UiCollection(new UiSelector().resourceId(StrUtils.settingList_Q)), objParent, getObj(objSelect[3], "android:id/switch_widget"));
            if (!obj.getText().equals("关闭")) obj.clickAndWaitForNewWindow();
            checkPoint("check status", obj.getText().equals("关闭"));
            logUtils.printLog("set battery success");
        } catch (Throwable e) {
            logUtils.printLog("set battery fail");
        } finally {
            mDevice.pressHome();
        }
    }

    @Test
    public void Case013_setBTName() {
        mDevice.pressHome();
        String name = cfgUtils.getCfg("bt_name=");
        logUtils.printLog("==start set BT name==");
        try {
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], "已连接的设备|已关联的设备");
            waitObj(objSelect[3], StrUtils.settingList_Q, 3);
            waitClickIfObjExist(objSelect[2], "连接偏好设置", 3);
            waitClickObj(objSelect[2], "蓝牙", 3);
            waitClickIfObjExist(objSelect[2], "关闭", 3);
            waitObj(objSelect[2], "设备名称", 10);
            if (!existObj(objSelect[0], name)) {
                clickObj(objSelect[2], "设备名称");
                waitObj(objSelect[3], "com.android.settings:id/edittext", 3);
                inputTxtToObj(objSelect[3], "com.android.settings:id/edittext", name);
                waitClickObj(objSelect[2], "重命名", 5);
            }
            checkPoint("check navigation bar style", existObj(objSelect[0], name));
            logUtils.printLog("set BT name success : " + name);
        } catch (Throwable e) {
            logUtils.printLog("set BT name fail : " + name);
        } finally {
            mDevice.pressHome();
        }
    }

    @Test
    public void Case014_setMultiUser() {
        mDevice.pressHome();
        String arg0 = cfgUtils.getCfg("standard_user=");
        String arg1 = cfgUtils.getCfg("child_user=");
        logUtils.printLog("==start set multi user==");
        try {
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], "用户和帐号");
            waitObj(objSelect[3], StrUtils.settingList_Q, 3);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], "多用户|用户");
            if (!Package.pac().isAppInstalled("com.android.chrome") &&
                    !existObj(objSelect[0], arg0)) {
                waitClickObj(objSelect[0], "添加用户", 3);
                waitClickIfObjExist(objSelect[0], "确定", 3);
                waitClickObj(objSelect[0], "一般用户", 3);
                waitClickObj(objSelect[0], "继续", 3);
                waitObj(objSelect[0], "姓名", 3);
                inputTxtToObj(objSelect[0], "姓名", arg0);
                waitClickObj(objSelect[0], "下一步", 3);
                waitClickObj(objSelect[0], "关闭", 20);
            }
            if (!Package.pac().isAppInstalled("com.android.chrome")
                    && !existObj(objSelect[0], arg1)) {
                waitClickObj(objSelect[0], "添加用户", 3);
                waitClickObj(objSelect[0], "学生用户", 3);
                waitClickObj(objSelect[0], "继续", 3);
                waitObj(objSelect[0], "姓名", 3);
                inputTxtToObj(objSelect[0], "姓名", arg1);
                clickObj(objSelect[0], "生日");
                waitClickObj(objSelect[0], "确定", 3);
                waitClickObj(objSelect[0], "年级", 3);
                waitClickObj(objSelect[0], "学龄前", 3);
                waitClickObj(objSelect[0], "确定", 3);
                waitClickObj(objSelect[0], "地区", 3);
                scrollReidClickObj("com.android.wantjoin.settings:id/region_recycler_view", objSelect[2], "北京");
                waitClickObj(objSelect[0], "确定", 3);
                waitClickObj(objSelect[0], "下一步", 3);
                waitClickObj(objSelect[0], "完成", 10);
                waitClickObj(objSelect[0], "关闭", 20);
                checkPoint("check status", existObj(objSelect[0], arg1));
                logUtils.printLog("set multi user success : " + arg1);
            }
            checkPoint("check status", existObj(objSelect[0], arg0));
            logUtils.printLog("set multi user success : " + arg0);
        } catch (Throwable e) {
            logUtils.printLog("set multi user fail : " + arg0);
        } finally {
            mDevice.pressHome();
        }
    }

    @Test
    public void Case015_closeKeyBoard() {
        mDevice.pressHome();
        logUtils.printLog("==start set keyboard==");
        if (Package.pac().isAppInstalled("com.google.android.inputmethod.latin")) {
            try {
                openApp(StrUtils.settingPac);
                waitObj(objSelect[3], StrUtils.settingList_Q, 10);
                scrollReidClickObj(StrUtils.settingList_Q, objSelect[0], "系统");
                waitObj(objSelect[3], StrUtils.settingList_Q, 3);
                scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], "语言和输入法");
                waitClickObj(objSelect[0], "虚拟键盘", 5);
                waitClickObj(objSelect[0], "Gboard", 5);
                waitClickObj(objSelect[0], "主题背景", 5);
                waitClickObj(objSelect[4], "Google 浅色主题", 5);
                waitObjCheck(objSelect[2], "按键边框.*", 3);
                if (!existObj(objSelect[0], "按键边框 关闭")) clickObj(objSelect[2], "按键边框.*");
                checkPoint("check status", existObj(objSelect[0], "按键边框 关闭"));
                clickObj(objSelect[0], "应用");
                logUtils.printLog("set keyboard success");
            } catch (Throwable e) {
                logUtils.printLog("set keyboard fail");
            } finally {
                mDevice.pressHome();
            }
        } else {
            logUtils.printLog("not find Gboard");
        }
    }

    @Test
    public void Case016_closeLenovoUpdate() {
        mDevice.pressHome();
        String sw = "com.tblenovo.whatsnewclient:id/sw_control";
        logUtils.printLog("==start set lenovo update==");
        try {
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[0], "系统");
            waitObj(objSelect[3], StrUtils.settingList_Q, 3);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], "联想功能更新");
            if (getTxtFromObj(objSelect[3], sw).equals("开启")) clickObj(objSelect[3], sw);
            checkPoint("check status", getTxtFromObj(objSelect[3], sw).equals("关闭"));
            logUtils.printLog("set lenovo update success");
        } catch (Throwable e) {
            logUtils.printLog("set lenovo update fail");
        } finally {
            mDevice.pressHome();
        }
    }

    @Test
    public void Case017_removeWidget() {
        String searchBox = "com.google.android.googlequicksearchbox:id/search_edit_frame";
        logUtils.printLog("==start remove widget==");
        int y = 50;
        for (int i = 0; i < 3; i++) {
            mDevice.pressHome();
            if (UiBase.existObj(UiBase.objSelect[3], searchBox)) {
                try {
                    UiBase.dragObj(UiBase.objSelect[3], searchBox, StrUtils.SCREEN_W / 2, y, 50);
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                y += 10;
                if (i == 2) logUtils.printLog("remove widget search box fail");
            } else {
                logUtils.printLog("remove widget search box success");
                break;
            }
        }
    }

//    23、	在设置-系统-开发者选项（如果没有开发者选项，在“关于平板电脑”页面连续点击7下“版本号”） 页面，把“不锁定屏幕”打开；

    @Test
    public void Case018_openUnlockScreen() {

        mDevice.pressHome();
        logUtils.printLog("==start open UnlockScreen==");
        try {
            UiScrollable list = new UiScrollable(new UiSelector().resourceId(StrUtils.settingList_Q));
            UiObject list1 = list.getChildByInstance(new UiSelector().resourceId("android:id/switch_widget"), 0);
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], StrUtils.settingSystem);
            waitObj(objSelect[3], StrUtils.settingList_Q, 5);
            waitClickObj(objSelect[0], "开发者选项", 5);
            waitObj(objSelect[3], StrUtils.settingList_Q, 5);
            if (list1.isChecked()) {
                logUtils.printLog("UnlockScreen already open ");
            } else {
                waitClickObj(objSelect[0], "不锁定屏幕", 5);
                checkPoint("check status", list1.isChecked());
                logUtils.printLog("open UnlockScreen Success");
            }
        } catch (Throwable e) {
            logUtils.printLog("open UnlockScreen fail" + e);
        } finally {
            mDevice.pressHome();
        }
    }

    //    24、	相册下，点击左上角菜单的“归档”，放置1张图片；
    @Test
    public void Case019_addArchive() {
        mDevice.pressHome();
        String pac = "com.google.android.apps.photos";
        UiScrollable archivelist = new UiScrollable(new UiSelector().resourceId("com.google.android.apps.photos:id/recycler_view"));
        logUtils.printLog("==start add picture to Archive==");
        for (int i = 0; i <= 3; i++) {
            try {
                if (Package.pac().isAppInstalled(pac)) {
                    openApp(pac);
                    waitClickIfObjExist(objSelect[3], "com.google.android.apps.photos:id/not_now_button", 5);
                    waitClickObj(objSelect[7], "android.widget.ImageButton", 5);
                    waitClickObj(objSelect[0], "归档", 3);
                    UiObject item = archivelist.getChildByInstance(new UiSelector().className("android.view.ViewGroup"), 1);
                    if (item.exists()) {
                        logUtils.printLog("archive picture already exist");
                        break;
                    } else {
                        waitClickObj(objSelect[3], "com.google.android.apps.photos:id/action_bar_add_to_archive", 3);
                        waitObj(objSelect[3], "com.google.android.apps.photos:id/recycler_view", 5);
                        item.click();
                        waitClickObj(objSelect[3], "com.google.android.apps.photos:id/action_button", 3);
                        checkPoint("check status", item.exists());
                        logUtils.printLog("add archive picture Success");
                        break;
                    }
                } else {
                    logUtils.printLog("no ROW" + pac);
                    break;
                }
            } catch (Throwable e) {
                logUtils.printLog("add archive picture fail");
            } finally {
                mDevice.pressHome();
            }
        }
    }

//    26、	下拉通知栏，编辑快捷图标，把“勿扰、录屏、飞行模式”添加到快捷图标第三行
//    29、	下拉通知，把录屏加到第二页后，点击开始，允许存储空间权限后，关闭录屏
//    30、	Lte版本把移动网络打开（需要SIM卡）
    @Test
    public void Case020_editShortcut() {
        HomeScreenInit.setAmarShortCut();
        HomeScreenInit.setAmarRecordVideo();
        HomeScreenInit.setLTE_network();

    }

    //    通知栏操作
    @Test
    public void Case021_NotificationBar() {
        mDevice.pressHome();
        logUtils.printLog("==start Notification bar==");
        HomeScreenInit.setShortCut();
        HomeScreenInit.setRecordVideo();
        try {
            mDevice.swipe(StrUtils.SCREEN_W / 2, 0, StrUtils.SCREEN_W / 2, StrUtils.SCREEN_H / 2, 50);
//            开启自动旋转屏幕
            waitObj(objSelect[3], "com.android.systemui:id/quick_qs_panel", 3);
            if (objChecked(objSelect[4], "自动旋转屏幕")) {
                logUtils.printLog("Auto-rotate screen already open");
            } else {
                waitClickObj(objSelect[4], "自动旋转屏幕", 3);
                checkPoint("check status", objChecked(objSelect[4], "自动旋转屏幕"));
                logUtils.printLog("open Auto-rotate screen Success");
            }
        } catch (Throwable e) {
            e.printStackTrace();
            logUtils.printLog("change Notification bar fail");
        } finally {
            mDevice.pressHome();
        }
    }

    @Test
    public void Case104_initApps() {
        AppInit.openAppStore();
        AppInit.openCalendar();
        AppInit.openSoundRecorder();
        AppInit.openNBUFiles();
        AppInit.openChrome();
    }

    @Test
    public void Case105_addHistory() {
        AppInit.addCallLogs();
        AppInit.addCalendarEvent();
        AppInit.addMapHistory();
    }


    private static void initLogs() throws Throwable {
        FileUtils.deleteFile(filePath + "ATS/logs/AtsLogs.txt"); // del old logs
        logUtils.printLog("[version]= V1.1.1_20200506");
        logUtils.printLog("[model name]=" + mDevice.executeShellCommand("getprop ro.product.model").replace("\n", ""));
        logUtils.printLog("[serial no]=" + mDevice.executeShellCommand("getprop ro.serialno").replace("\n", ""));
        logUtils.printLog("[build info]=" + mDevice.executeShellCommand("getprop ro.build.description").replace("\n", ""));
    }

    private void enterWLAN() throws Throwable {
        if (existObj(objSelect[2], StrUtils.wifi) && existObj(objSelect[3], StrUtils.frictionIcon)) {
            SystemClock.sleep(waitTime);
        } else {
            mDevice.pressHome();
            openApp(StrUtils.settingPac);
            waitObj(objSelect[3], StrUtils.settingList_Q, 10);
            scrollReidClickObj(StrUtils.settingList_Q, objSelect[2], StrUtils.settingNetwork);
            waitClickObj(objSelect[2], StrUtils.wifi, 5);
            waitObj(objSelect[3], StrUtils.switch_widget, 5);
            if (getTxtFromObj(objSelect[3], StrUtils.switch_widget).matches(StrUtils.off)) {
                clickObj(objSelect[3], StrUtils.switch_widget);
                SystemClock.sleep(waitTime * 10);
            }
            SystemClock.sleep(waitTime * 5);
        }
    }


}
